package com.wk1un2.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wk1un2.entity.ProductPict;
import com.wk1un2.service.ProductPictService;
import com.wk1un2.util.Result;
//商品图片控制器
@Controller
public class ProductPictController {
	@Autowired
	ProductPictService service;

	@RequestMapping("/Backstage/getAllProductPict")
	@ResponseBody
	public Object getAll(@RequestParam("page") int page, @RequestParam("limit") int limit,
			@RequestParam("p_name") String p_name) {

		if (p_name == null || p_name == "") {
			p_name = null;
		}
		List<ProductPict> ls = service.getAll((page - 1) * limit, limit, p_name);
		Result res = new Result(0, "", service.count(), ls);
		return res;
	}

//	
	@RequestMapping("/Backstage/addProductPict")
	@ResponseBody
	public Object add(@RequestParam Map<String, Object> map) {

		System.out.println(map.get("p_name"));
		int i = service.add(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//	޸
	@RequestMapping("/Backstage/updateProductPict")
	@ResponseBody
	public Object update(@RequestParam Map<String, Object> map) {
		System.out.println(map.get("p_name"));
		int i = service.update(map);
		Result res = new Result(0, "", i, i);
		return res;
	}

//	ɾ
	@RequestMapping("/Backstage/deleteProductPict")
	@ResponseBody
	public Object delete(@RequestParam("pp_id") int pp_id) {
		System.out.println(pp_id);
		int i = service.delete(pp_id);
		Result res = new Result(0, "", i, i);
		return res;
	}
}
